package com.quik.web.token.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.quik.entity.DtaToken;
import com.quik.entity.DtaTokenType;
import com.quik.entity.TokenTypeBoundProduct;
import com.quik.web.token.mapper.TokenDao;

/**
 * 功能说明：
 *      接口TokenService的实现类
 * @author Administrator
 *
 */
@Service
public class TokenServiceImpl implements TokenService {
	
	@Autowired
	private TokenDao dao;

	/**
	 * 根据条件查询手牌类型数量
	 * @param tokenTypeName
	 * @param productName
	 * @param productNo
	 * @return
	 * @throws Exception
	 */
	@Override
	public int findTokenTypeCount(String tokenTypeName, String productName, String productNo) throws Exception{
		int count = dao.findTokenTypeCount(tokenTypeName, productName, productNo);
		return count;
	}
	
	/**
	 * 根据条件查询手牌类型列表（分页）
	 * @param tokenTypeName
	 * @param productName
	 * @param productNo
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findTokenType(String tokenTypeName, String productName, String productNo, int page, int rows) throws Exception{
		List list = dao.findTokenType(tokenTypeName, productName, productNo, page, rows);
		return list;
	}
	
	/**
	 * 检查手牌类型名称是否重复
	 * @param tokenTypeName
	 * @return 重复返回True,否则返回false
	 * @throws Exception
	 */
	@Override
	public boolean checkTokenTypeName(String tokenTypeName) throws Exception{
		int count = dao.findTokenTypeCountByTokenTypeName(tokenTypeName);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增手牌类型
	 * @param tokenType
	 * @throws Exception
	 */
	@Override
	public void addTokenType(DtaTokenType tokenType) throws Exception{
		TokenTypeBoundProduct bound = new TokenTypeBoundProduct();
		bound.setCrt_date(tokenType.getCrt_date());
		bound.setCrt_user(tokenType.getCrt_user());
		bound.setProduct_no(tokenType.getProductNo());
		
		dao.addTokenType(tokenType, bound);
	}
	
	/**
	 * 根据条件查询手牌数量
	 * @return
	 */
	@Override
	public int findTokenCount(String tokenNo, String tokenTypeName) throws Exception{
		int count = dao.findTokenCount(tokenNo, tokenTypeName);
		return count;
	}
	
	/**
	 * 根据条件查询手牌列表（分页）
	 * @param tokenNo
	 * @param tokenTypeName
	 * @param page
	 * @param rows
	 * @return
	 * @throws Exception
	 */
	@Override
	public List findToken(String tokenNo, String tokenTypeName, Integer intPage, Integer pageSize) throws Exception{
		List list = dao.findToken(tokenNo, tokenTypeName, intPage, pageSize);
		return list;
	}
	
	/**
	 * 检查手牌编号是否重复
	 * @param tokenNo
	 * @return 若重复返回true, 否则返回false
	 * @throws Exception
	 */
	@Override
	public boolean checkTokenNo(String tokenNo) throws Exception{
		int count = dao.findTokenCountByTokenNo(tokenNo);
		
		if(count > 0)
			return true;
		else
			return false;
	}
	
	/**
	 * 新增手牌
	 * @param token
	 * @throws Exception
	 */
	@Override
	public void addToken(DtaToken token) throws Exception{
		dao.addToken(token);
	}
}
